﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace ZSoftInstagram.UI.Web.Infrastructure.IOC
{
    public class StructureMapDependencyResolver : IDependencyResolver
    {
        public object GetService(Type serviceType)
        {
            if (serviceType.IsAbstract || serviceType.IsInterface)
            {
                return ObjectFactory.Container.TryGetInstance(serviceType);
            }
            return ObjectFactory.Container.GetInstance(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return ObjectFactory.Container.GetAllInstances(serviceType).Cast<object>();
        }
    }
}